package com.mh.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * 
 * @ModelCoreReference [platform:/resource/demo-mh/.springDSL/com/mh/domain/AppRole.datatype]
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllAppRoles", query = "select myAppRole from AppRole myAppRole"),
		@NamedQuery(name = "findAppRoleByApplication", query = "select myAppRole from AppRole myAppRole where myAppRole.application = ?1"),
		@NamedQuery(name = "findAppRoleByApplicationContaining", query = "select myAppRole from AppRole myAppRole where myAppRole.application like ?1"),
		@NamedQuery(name = "findAppRoleByDescription", query = "select myAppRole from AppRole myAppRole where myAppRole.description = ?1"),
		@NamedQuery(name = "findAppRoleByDescriptionContaining", query = "select myAppRole from AppRole myAppRole where myAppRole.description like ?1"),
		@NamedQuery(name = "findAppRoleById", query = "select myAppRole from AppRole myAppRole where myAppRole.id = ?1"),
		@NamedQuery(name = "findAppRoleByPrimaryKey", query = "select myAppRole from AppRole myAppRole where myAppRole.id = ?1"),
		@NamedQuery(name = "findAppRoleByRoleName", query = "select myAppRole from AppRole myAppRole where myAppRole.roleName = ?1"),
		@NamedQuery(name = "findAppRoleByRoleNameContaining", query = "select myAppRole from AppRole myAppRole where myAppRole.roleName like ?1") })
@Table(schema = "MHTEST", name = "APP_ROLE")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "demo-mh/com/mh/domain", name = "AppRole")
public class AppRole implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@XmlElement
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_app_role")
	@SequenceGenerator(name = "seq_app_role", sequenceName = "seq_app_role")
	Integer id;

	/**
	 */

	@Column(name = "APPLICATION", length = 20, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=20, message="{com.vit.nulo}")
	String application;

	/**
	 */

	@Column(name = "ROLE_NAME", length = 60, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=60, message="{com.vit.tamanho.maximo}")
	String roleName;

	/**
	 */

	@Column(name = "DESCRIPTION", length = 60, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=60, message="{com.vit.tamanho.maximo}")
	String description;

	
	@ManyToMany(targetEntity=AppUser.class, mappedBy="appRole")
	private Set<AppUser> appUsers = new HashSet<AppUser>(0);
	
	
	@ManyToMany(
			targetEntity=AppUser.class,
			mappedBy="APP_USER_ROLE"
	)
	
	@JsonIgnore
	public Set<AppUser> getAppUsers() {
		return appUsers;
	}

	public void setAppUsers(Set<AppUser> appUsers) {
		this.appUsers = appUsers;
	}

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */

	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setApplication(String application) {
		this.application = application;
	}

	/**
	 */
	public String getApplication() {
		return this.application;
	}

	/**
	 */
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	/**
	 */
	public String getRoleName() {
		return this.roleName;
	}

	/**
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 */
	public String getDescription() {
		return this.description;
	}
	
	
	private Integer appUserId;
	

	public Integer getIntAppUserId() {return appUserId;}

	public void setAppUserId(Integer appUserId) {this.appUserId = appUserId;}

	/**
	 */
	public AppRole() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(AppRole that) {
		setId(that.getId());
		setApplication(that.getApplication());
		setRoleName(that.getRoleName());
		setDescription(that.getDescription());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("application=[").append(application).append("] ");
		buffer.append("roleName=[").append(roleName).append("] ");
		buffer.append("description=[").append(description).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof AppRole))
			return false;
		AppRole equalCheck = (AppRole) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
